<?php

header("Content-type:text/html;charset=utf-8");
session_start();

//连接数据库
$server = 'localhost';
$user = 'root';
$psw = 'root';
$db = 'qq';
$conn = new PDO("mysql:host=$server;dbname=$db",$user,$psw);
//根据session_id找到当前用户信息
$id = isset($_SESSION['id'])?$_SESSION['id']:0;
$check = $conn->query("select * from user where id=$id");
$res = $check->fetch(PDO::FETCH_ASSOC);


//找到所有用户信息，展示在联系人列表
$check_query = $conn->query("select * from user");
$result = $check_query->fetchAll(PDO::FETCH_ASSOC);


//找到聊天对象
$per_id = isset($_GET['id'])?$_GET['id']:0;
$per =  $conn->query("select * from user where id=$per_id");
$per_res = $per->fetch(PDO::FETCH_ASSOC);


//从数据库取出聊天信息展示聊天窗口
//聊天 记录 有两种 类型 ，一种是 我发送给A的  
//一种 是 我接收到的，A发给我 的  
//这条 sql 语句 只获取到了第一种情况
//你把第二种情况加上就可以了
$sql = "SELECT * FROM talk 
		WHERE ((fid=$id AND tid=$per_id) OR  (fid=$per_id AND tid=$id))
		ORDER BY addtime ASC";

$talk_about =  $conn->query($sql);
$all = $talk_about->fetchAll(PDO::FETCH_ASSOC);
 


//自动刷新页面



include 'talk.html';


